package com.lz.football.module.youngTrain.view
{
	import com.common.utils.DisplayObjectUtil;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.youngTrain.vo.PlayerChildInfoVo;
	import com.lz.football.module.base.IComponent;
	import com.lz.football.module.youngTrain.item.PlayerChildItem;
	
	import flash.display.Sprite;

	/**
	 *显示球童面板 
	 * @author lake
	 * 
	 */	
	public class ShowPlayerChildPanel extends Sprite implements IComponent
	{
		/**
		 *球童位置列表 12个 
		 */		
		public var posList 		:Array = [];
		/**
		 *item 列表 
		 */		
		private var itemList 	:Array = [];
		
		public function ShowPlayerChildPanel()
		{
			super();
		}
		/**
		 *初始化 
		 * 
		 */	
		public function initUI(view:Object=null):void
		{
			posList.push({x:283,y:92});
			posList.push({x:191,y:119});
			posList.push({x:345,y:145});
			posList.push({x:386,y:39});
			posList.push({x:433,y:105});
			posList.push({x:66,y:46});
			posList.push({x:13,y:139});
			posList.push({x:110,y:98});
			posList.push({x:487,y:37});
			posList.push({x:131,y:165});
			posList.push({x:214,y:37});
			posList.push({x:508,y:153});
			var item :PlayerChildItem;
			for(var i :int = 0;i < 12;i++)
			{
				item = new PlayerChildItem();
				item.initUI();
				itemList.push(item);
			}
		}
		/**
		 *注册事件 
		 * 
		 */	
		public function addEvtListener():void
		{
		}
		/**
		 *显示球童 
		 * 
		 */		
		public function showPlayer():void
		{
			var playerChildList :Array = AppData.getInstance().youngTrainManager.youngTrainInfoVo.playerChildList;
			var item :PlayerChildItem;
			DisplayObjectUtil.removeAllChildren(this);
			var childInfo :PlayerChildInfoVo;
			for(var i :int = 0;i < playerChildList.length;i++)
			{
				childInfo = playerChildList[i];
				if(childInfo.index <= 0 )
				{
					continue;
				}
				item = itemList[i];
				item.data = childInfo;
				item.x = posList[childInfo.index - 1].x;
				item.y = posList[childInfo.index - 1].y;
				this.addChild(item);
			}
		}
		/**
		 *更新球童 
		 */		
		public function updatePlayer():void
		{
			var indexs :Array = AppData.getInstance().youngTrainManager.saleOrgetChildIndexs;
			var i :int;
			for each(var item :PlayerChildItem in itemList)
			{
				if(item.data == null)continue;
				i = indexs.indexOf(item.data.index)
				if(i != -1)
				{
					if(item.parent)
					{
						item.parent.removeChild(item);
					}
					AppData.getInstance().youngTrainManager.removePlayerChildByIndex(item.data.index);
					indexs.splice(i,1);
				}
			}
			AppData.getInstance().youngTrainManager.saleOrgetChildIndexs = [];
		}
		/**
		 *删除事件 
		 * 
		 */	
		public function removeEvtListener():void
		{
		}
		/**
		 *销毁 
		 * 
		 */	
		public function destroyView():void
		{
			removeEvtListener();
			for each(var item :PlayerChildItem in itemList)
			{
				item.destroyView();
			}
			itemList = null;
		}
	}
}